// components/editerFooter/index.js
const { formatDate } = require('../../utils/util')

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        // publishFN: Function
        toptimes: String,
        sel_top:Number,
        topInfo: Array,
        type_id:Number
    },

    /**
     * 组件的初始数据
     */
    data: {
        checked: true,
        checked1: true,
        date:formatDate(new Date()),
        index: 0,
        topInfo: Array,
        timeArr: ['七天', '半个月', '一个月', '一季度', '半年', '一年'],
        currentDate: new Date().getTime(),
        show: false,
        type_id:0,
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`
            } else if (type === 'month') {
                return `${value}月`
            }
            return value
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(event) {
          if (this.data.type_id == 3 || this.data.type_id=='3'){
            wx.showToast({
              title: '商业信息发布必须置顶',
              icon: 'none',
              duration: 2000
            })
            return false;
          }
            this.setData({
                checked: event.detail
            })
        },
        onChange1(event) {
            this.setData({
                checked1: event.detail
            })
        },
        publish() {
            if (this.data.checked && !this.data.checked1) {
                wx.showToast({
                    title: '请先同意入驻协议',
                    icon: 'none',
                    duration: 2000
                })
                return false
            }
            this.triggerEvent('publishFN', {
                checked: this.data.checked,
                sel_top:this.data.index,
                sel_start_time:this.data.date
            });

        },
        bindPickerChange: function(e) {
            this.setData({
                index: e.detail.value
            })
        },
        onInput(event) {
            var d = new Date(event.detail);
            d = formatDate(d);
            this.setData({
                currentDate: event.detail,
                date: d
            })
        },
        togglePicker() {
            this.setData({
                show: !this.data.show
            })
        },

        jumpToAgreement() {
            wx.navigateTo({
                url: '/pages/login/agreement'
            })
        }
    }
})
